package fr.nantes.guidetouristique.adapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import fr.nantes.guidetouristique.R;

public class ListeAdapter extends BaseAdapter {

	private List<String> liste;
	private LayoutInflater inflater;

	public ListeAdapter(List<String> listeParcs, Context context) {
		super();
		this.liste = listeParcs;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return liste.size();
	}

	@Override
	public Object getItem(int position) {
		return liste.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	private class ViewHolder {
		TextView textView;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		String string = liste.get(position);
		if (convertView == null) {
			holder = new ViewHolder();
			if (string.length() > 10) {
				convertView = inflater.inflate(R.layout.parc, null);
				holder.textView = (TextView) convertView
						.findViewById(R.id.intituleParc);
			} else {
				convertView = inflater.inflate(R.layout.separateur, null);
				holder.textView = (TextView) convertView
						.findViewById(R.id.separateur);
				holder.textView.setClickable(false);
			}
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.textView.setText(string);
		return convertView;
	}
}
